/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ThemNhanVienDialog.java
 *
 * Created on Jul 3, 2010, 9:39:51 AM
 */

package GUI;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author May2
 */
public class ThemNhanVienDialog extends javax.swing.JDialog {

    /** Creates new form ThemNhanVienDialog */
    public ThemNhanVienDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

//    public void hienThiNhanVien(ArrayList<NhanVienPOJO> list){
//        //Tạo các cột trên Jtable
//        DefaultTableModel dtm = new DefaultTableModel();
//        dtm.addColumn("Mã Nhân Viên");
//        dtm.addColumn("Tên Nhân Viên");
//        dtm.addColumn("Ngày Sinh");
//        dtm.addColumn("Địa Chỉ");
//        dtm.addColumn("Email");
//        dtm.addColumn("Điện Thoại");
//        dtm.addColumn("Tên Phòng Ban");
//        //Tạo model
//        dtm.setRowCount(list.size());
//        for(int i=0; i<list.size(); i++){
//            dtm.setValueAt(list.get(i).getMaNhanVien(),i,0);
//            dtm.setValueAt(list.get(i).getTenNhanVien(),i,1);
//            dtm.setValueAt(list.get(i).getNgaySinh(),i,2);
//            dtm.setValueAt(list.get(i).getDiaChi(),i,3);
//            dtm.setValueAt(list.get(i).getEmail(),i,4);
//            dtm.setValueAt(list.get(i).getDienThoai(),i,5);
//            dtm.setValueAt(list.get(i).getTenPhongBan(),i,6);
//        }
//        this.jtbDanhSach.setModel(dtm);
//        this.jtbDanhSach.changeSelection(0, 0, false, false);
//    }
    public void hienThiNhanVienAll(){
//        ArrayList<NhanVienPOJO> list = NhanVienBUS.selectNhanVien();
//        this.hienThiNhanVien(list);
    }
    public void hienThiPhongBan(){
//        ArrayList<PhongBanPOJO> list = PhongBanBUS.selectPhongBanAll();
//        //Đọc dữ liệu
//        DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
//        for(int i=0; i<list.size(); i++){
//            //Đọc từng dòng
//            Vector ct = new Vector();
//            ct.add(list.get(i).getMaPhongBan());
//            ct.add(list.get(i).getTenPhongBan());
//            //Thêm một dòng vào model của JComboBox
//            dcbm.addElement(ct);
//        }
//        //Gán model cho JComboBox
//        this.jcbPhongBan.setModel(dcbm);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jlbTenNhanVien = new javax.swing.JLabel();
        jtfTenNhanVien = new javax.swing.JTextField();
        jcbPhongBan = new javax.swing.JComboBox();
        jbtThoat = new javax.swing.JButton();
        jlbPhongBan = new javax.swing.JLabel();
        jbtThem = new javax.swing.JButton();
        jbtCapNhat = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbDanhSach = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("TIẾP NHẬN NHÂN VIÊN");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông Tin Nhân Viên"));

        jlbTenNhanVien.setText("Tên Nhân Viên");

        jbtThoat.setText("Thoát");
        jbtThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThoatActionPerformed(evt);
            }
        });

        jlbPhongBan.setText("Phòng Ban");

        jbtThem.setText("Thêm");
        jbtThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThemActionPerformed(evt);
            }
        });

        jbtCapNhat.setText("Cập Nhật");
        jbtCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCapNhatActionPerformed(evt);
            }
        });

        jtbDanhSach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jtbDanhSach);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jlbTenNhanVien)
                                .addGap(26, 26, 26))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jbtThem, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jbtCapNhat)
                                .addGap(18, 18, 18)
                                .addComponent(jbtThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(26, 26, 26))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtfTenNhanVien)
                                    .addComponent(jcbPhongBan, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(18, 18, 18))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jlbPhongBan)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlbTenNhanVien)
                            .addComponent(jtfTenNhanVien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlbPhongBan)
                            .addComponent(jcbPhongBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(235, 235, 235)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbtThoat)
                            .addComponent(jbtCapNhat)
                            .addComponent(jbtThem))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThemActionPerformed
        // TODO add your handling code here:
//        NhanVienPOJO nv = new NhanVienPOJO();
//        nv.setTenNhanVien(this.jtfTenNhanVien.getText());
//        nv.setTenTaiKhoan(this.jtfTenTaiKhoan.getText());
//        nv.setMatKhau(this.jpfMatKhau.getText());
//        nv.setNgaySinh(this.jtfNgaySinh.getText());
//        nv.setDiaChi(this.jtfDiaChi.getText());
//        nv.setEmail(this.jtfEmail.getText());
//        nv.setDienThoai(this.jtfDienThoai.getText());
//        Vector vt = (Vector)this.jcbPhongBan.getSelectedItem();
//        nv.setMaPhongBan((Integer)vt.get(0));
//
//        int n = NhanVienBUS.insertNhanVien(nv);
//        if(n==1){
//                JOptionPane.showMessageDialog(this, "Thêm thành công!!!");
//                this.hienThiNhanVienAll();
//        } else {
//                JOptionPane.showMessageDialog(this, "Thêm thất bại.");
//        }

}//GEN-LAST:event_jbtThemActionPerformed

    private void jbtCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCapNhatActionPerformed
        // TODO add your handling code here:
        this.hienThiNhanVienAll();
}//GEN-LAST:event_jbtCapNhatActionPerformed

    private void jbtThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThoatActionPerformed
        // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_jbtThoatActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        this.hienThiNhanVienAll();
        this.hienThiPhongBan();
    }//GEN-LAST:event_formWindowOpened

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ThemNhanVienDialog dialog = new ThemNhanVienDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtCapNhat;
    private javax.swing.JButton jbtThem;
    private javax.swing.JButton jbtThoat;
    private javax.swing.JComboBox jcbPhongBan;
    private javax.swing.JLabel jlbPhongBan;
    private javax.swing.JLabel jlbTenNhanVien;
    private javax.swing.JTable jtbDanhSach;
    private javax.swing.JTextField jtfTenNhanVien;
    // End of variables declaration//GEN-END:variables

}
